﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FullThrustLogic.Helper;
using FullThrustLogic.ShipComponent;
using FullThrustLogic.ShipComponent.Weapon;

namespace FullThrustLogic.Core
{
    public class Game
    {
        public Map Map
        {
            get; set;
        }

        public List<Player> Players
        {
            get; set;
        }

        public int TotalNumberOfRounds
        {
            get; set;
        }

        public int RoundNumber
        {
            get; set;
        }

        public List<Ship> GetShipsInRange(Ship targetingShip,  
            iWeapon targetingWeapon,
            TypeOfPlayer playerType)
        {

            double distance = 0;
            List<Ship> shipsInRange = new List<Ship>();

            
            foreach(Player player in Players)
            {
                if(player.PlayerType != playerType)
                {
                    foreach (Ship ship in player.Ships)
                    {
                        distance = XYHelper.DistanceBetweenPoints(targetingShip.PositionX, targetingShip.PositionY,
                                                                  ship.PositionX, ship.PositionY);

                        if (distance <= targetingWeapon.Range)
                        {
                            if (targetingWeapon.InArc(targetingShip, ship))
                            {
                                shipsInRange.Add(ship);
                            }
                        }
                    }
                }
            }

            return shipsInRange;
        }

        public void Create(int mapHeight, int mapWidth, int numberOfPlayers)
        {
            Map = new Map(mapHeight, mapWidth);

            Players = new List<Player>();

            Players.Add(new Player(TypeOfPlayer.Player1));
            Players.Add(new Player(TypeOfPlayer.Player2));
        }
    }
}
